package com.yeban.javase.day06.test04_localtime;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/14
 *
 * 4.求上个月的第三天是星期几？
 */
public class test04 {

    // minusMonths 回到上个月      withDayOfMonth 找到第三天      getDayOfWeek 判断周几
    public static void main(String[] args) {

        // 获得当前时间
        LocalDate today = LocalDate.now();

        // 回到上个月第三天
        LocalDate lastTime = today.minusMonths(1).withDayOfMonth(3);

        // 获取星期几信息
        int weekDay = lastTime.getDayOfWeek().getValue();    //getDayOfWeek返回值为：DayOfWeek
        String weekDayStr = getDayOFWeek(weekDay);  // 索引 1-7 周一-周日

        // 格式转换 ——> String类型输出
        System.out.println("上个月的第三天是" + weekDayStr);
    }

    public static String getDayOFWeek(int index) {
        String[] strs = {"", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"};
        return strs[index];
    }

}
